home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / graphicgems4.lha / GemsIV / vec_mat / ray / Camera.c next >
Encoding:
C/C++ Source or Header  |  1995-02-06  |  1.4 KB  |  42 lines

  1. #include "Camera.h"
  2.  
  3. /************************************************************************
  4. *                                    *
  5. * These methods set the field of view of the camera. They transform    *
  6. * the field of view between a user representation (2 angles specified    *
  7. * in degrees) an internal representation (the size of the film square). *
  8. *                                    *
  9. ************************************************************************/
  10.  
  11. void Camera::setFieldOfView(vec2& v)
  12. { film_size = (v * (M_PI / 360.0)).apply(&tan); }
  13.  
  14. vec2 Camera::fieldOfView()
  15. { return (360.0 * M_1_PI) * (vec2(film_size).apply(&atan)); }
  16.  
  17. /************************************************************************
  18. *                                    *
  19. * This method transforms a 2D point located on the film plane into a    *
  20. * normalized ray. The method only returns the direction of the ray.    *
  21. * The origin can be found by asking the camera its position.        *
  22. *                                    *
  23. ************************************************************************/
  24.  
  25. vec3 Camera::pointToRay(vec2&  p)
  26. { return orient * vec3(prod(film_size, p), -1.0).normalize(); }
  27.  
  28. /************************************************************************
  29. *                                    *
  30. * Input from stream.                            *
  31. *                                    *
  32. ************************************************************************/
  33.  
  34. istream& operator >> (istream& s, Camera& a)
  35. {
  36. vec2    fov;
  37.  
  38. s >> *((Object3D*) &a);
  39. s >> fov;
  40. a.setFieldOfView(fov);
  41. return s;
  42. }